package main

import (
	"fmt"
	"function"
)

var bianliang1 int = 123
var bianliang2 = 123

//bianliang3 := 123   这种变量声明方式只能是局部变量
//int = 0 string="" bool=false  *int =nil

//结构体概念
type name_strut struct {
	ID int
	id int
}

//定义结构体变量
var data1 name_strut

//结构体方法
func (this name_strut) test1() {
	fmt.Println("test1")
	return
}

func (this *name_strut) test2() {
	fmt.Println("test2")
	return
}

//map定义方式1
var map_name map[string]int

//map注意点：map使用之前，要初始化操作
func init() {
	map_name = make(map[string]int)
}
func init() {
	fmt.Println("MAP学习init")
}

//结构体和map
var map_name2 map[string]name_strut1

type name_strut1 struct {
	id int
}

func init() {
	map_name2 = make(map[string]name_strut1)
}

func main() {
	fmt.Println("变量的3种定义方式")
	var bianliang1 int = 123
	fmt.Println(bianliang1)
	var bianliang2 = 123
	fmt.Println(bianliang2)
	bianliang3 := 123
	fmt.Println(bianliang3)
	fmt.Println("所有变量都被初始化维零值")
	var biangliang4 *int
	fmt.Println(biangliang4)
	fmt.Println("常量")
	const PI = 3.1415
	fmt.Println(PI)
	fmt.Println("数据的初始化递增和iota的连用")
	const (
		INIT = "33"
		INIT1
		INIT2
		ONE = iota
		TWO
		THREE = "22"
		FOUR
	)

	fmt.Println("INIT", INIT)
	fmt.Println("INIT1", INIT1)
	fmt.Println("INIT2", INIT2)
	fmt.Println("ONE", ONE)
	fmt.Println("TWO", TWO)
	fmt.Println("THREE", THREE)
	fmt.Println("FOUR", FOUR)
	fmt.Println("控制语句")
	//if else
	//for
	//switch
	var ruguo int = 100
	if ruguo == 100 {
		fmt.Println("if")
	} else if ruguo == 101 {
		fmt.Println("else if")
	} else {
		fmt.Println("else")
	}
	for i := 0; i < 10; i++ {
		fmt.Println("for", i)
	}
	switch ruguo {
	case 100:
		fmt.Println("100")
	default:
		fmt.Println("default")
	}
	fmt.Println("结构体")
	//赋值方式1
	data1.ID = 233
	data1.id = 666
	fmt.Println("结构体1", data1)
	//赋值方式2
	data2 := name_strut{
		ID: 99,
		id: 00,
	}
	fmt.Println("结构体2", data2)
	data2.test1()
	data3 := &name_strut{
		ID: 999,
		id: 888,
	}
	fmt.Println("结构体指针", data3)
	data3.test2()

	fmt.Println("调用同包下的函数，函数名首字母必须大写", Wjp("wjp"))

	function.Test()
	function.Test2()

	fmt.Println("map使用之前，要运行初始化")
	fmt.Println("map存储是无序的，底层是hash")
	fmt.Println("map并发是不安全的")

	//map定义方式2
	map_name1 := make(map[string]int)
	map_name1["2"] = 22
	fmt.Println("map_name1:", map_name1)

	map_name["1"] = 99
	fmt.Println("map_name:", map_name)

	fmt.Println("map_name:")
	data4 := name_strut1{
		id: 900,
	}
	map_name2["jiegouti1"] = data4
	data5 := name_strut1{
		id: 9900,
	}
	map_name2["jiegouti2"] = data5
	fmt.Println("map_name:", map_name2)
}
